package com.cx.service.impl;

import com.cx.mapper.ConcernMapper;
import com.cx.pojo.Concern;
import com.cx.pojo.ConcernExample;
import com.cx.service.ConcernService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ConcernServiceImpl implements ConcernService {

    @Autowired
    ConcernMapper concernMapper;

//    我的关注功能
    @Override
    public List<Concern> selectByConcerningId(Integer concerningId) {
        ConcernExample concernExample = new ConcernExample();
        ConcernExample.Criteria criteria = concernExample.createCriteria();
        criteria.andConcerningIdEqualTo(concerningId);
        List<Concern> concernList = concernMapper.selectByExample(concernExample);
        return concernList;
    }

//    我的粉丝功能
    @Override
    public List<Concern> selectByConcernedId(Integer concernedId) {
        ConcernExample concernExample = new ConcernExample();
        ConcernExample.Criteria criteria = concernExample.createCriteria();
        criteria.andConcernedIdEqualTo(concernedId);
        List<Concern> concernedList = concernMapper.selectByExample(concernExample);
        return concernedList;
    }



//    取消关注
//    @Override
//    public Integer deleteConcern(Integer concernedId) {
//        Integer rows = concernMapper.deleteByConcernedId(concernedId);
//        return rows;
//    }




    @Override
    public Integer insertConcern(Concern concern) {
        Integer rows = concernMapper.insertSelective(concern);
        return rows;
    }

    @Override
    public Integer deleteConcern(String userName, String userByName) {
        ConcernExample concernExample = new ConcernExample();
        ConcernExample.Criteria criteria = concernExample.createCriteria();
        criteria.andOther1EqualTo(userName);
        criteria.andOther2EqualTo(userByName);
        Integer rows = concernMapper.deleteByExample(concernExample);
        return rows;
    }

    @Override
    public List<Concern> selectByUserNameAndUserByName(String userName, String userByName) {
        ConcernExample concernExample = new ConcernExample();
        ConcernExample.Criteria criteria = concernExample.createCriteria();
        criteria.andOther1EqualTo(userName);
        criteria.andOther2EqualTo(userByName);
        List<Concern> concerns = concernMapper.selectByExample(concernExample);

        return concerns;
    }

    @Override
    public List<Concern> selectByOther1Name(String userName) {

        ConcernExample concernExample = new ConcernExample();
        ConcernExample.Criteria criteria = concernExample.createCriteria();
        criteria.andOther1EqualTo(userName);
//        criteria.andOther2EqualTo(userByName);
        List<Concern> concerns = concernMapper.selectByExample(concernExample);

        return concerns;
    }

    @Override
    public List<Concern> selectByOther2Name(String userName) {
        ConcernExample concernExample = new ConcernExample();
        ConcernExample.Criteria criteria = concernExample.createCriteria();
        criteria.andOther2EqualTo(userName);
//        criteria.andOther2EqualTo(userByName);
        List<Concern> concerns = concernMapper.selectByExample(concernExample);

        return concerns;

    }

    @Override
    public Integer deleteConcern(String userName) {
        ConcernExample concernExample = new ConcernExample();
        ConcernExample.Criteria criteria = concernExample.createCriteria();
        criteria.andOther1EqualTo(userName);
//        criteria.andOther2EqualTo(userByName);
        Integer rows = concernMapper.deleteByExample(concernExample);
        return rows;
    }
}

